*----------------------------------------------------------------------------------------------------------	* 
* RESEARCHERS:		Emtiaz Hritan, Tim Bruckner									   							*
* PROGRAMMED BY:	Emtiaz Hritan																			*
* DESCRIPTION:      The Politics of Birth: How Local Representation Shapes Maternal-Infant Outcomes				 						 	                                                           *
* CREATED:			Aug. 27, 2025																		   	*
* LAST MODIFIED:	Jan. 27, 2026													       					*
*----------------------------------------------------------------------------------------------------------	*




clear all
set more off
* Set local paths
* Set this local datapath equal to the folder location for data
	local datapath "C:\Users\name\Replication Files Politics of Birth\Data"
* Set this local outputpath equal to the folder location for outcome like tables
	local outputpath "C:\Users\name\Replication Files Politics of Birth\Outcome"
	
	
* Install necessary packages
ssc install reghdfe
ssc install ftools
ssc install grstyle, replace
ssc install palettes, replace
ssc install colrspace, replace
ssc install ppmlhdfe, replace 
ssc install jwdid, replace 
ssc install csdid, replace 
ssc install drdid, replace 
ssc install did_imputation, replace
ssc install frause, replace
frause mpdta.dta, clear
ssc install hdfe, replace 
ssc install event_plot, replace
ssc install addplot, replace


**********************************************************************
** Table 1: Summary Statistics of County-Year Variables,1989–2021   **
**********************************************************************

clear all
* Import covariates file
use "`datapath'\all_covariates", clear 
* Election data ranges from 1989 to 2021; limit the covariates to this ranges
keep if inrange(year, 1989, 2021)
tempfile tempdata
    save `tempdata' 

* Import the cleaned county-level election data
use "`datapath'\county_election.dta"
merge 1:1 county_fips year using `tempdata'
keep if _merge==3
drop _merge

* Varibles included in this balance test: LaborForce Employed UnemploymentRate Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus code2013 earnings transfers. The control group is "Never elected any racial minority" now. 

* Define a local macro with all the "number" variables
local vars "LaborForce Employed Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus earnings transfers"

* Loop through each variable and scale it down by dividing by 1,000
foreach var of local vars {
    replace `var' = `var' / 1000
}


* Summary statistics

local vars "share_female share_black share_hispanic share_asian share_democrat LaborForce Employed UnemploymentRate Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus code2013 earnings transfers"

eststo clear 
eststo summary: quietly estpost summarize `vars' 

esttab summary, ///
    cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)) count(fmt(0))") ///
    nomtitle nonumber 

esttab summary using "summary_statistics.tex", tex replace ///
    cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)) count(fmt(0))") ///
    nomtitle nonumber 

eststo clear




**********************************************************************************
** Table A2: Summary Statistics of County-Year Birth Outcomes,1995–2019         **
**********************************************************************************
clear all 
use "`datapath'\final.dta"


*Build rates (guards for zero denominators)

gen ptb_rate_male           = 100  * births_ptb_male     / births_male           if births_male>0   // %
gen ptb_rate_female           = 100  * births_ptb_fem    / births_female        if births_female>0   // %

* Let's drop counties with low births 
drop if births_all < 100

* Summary statistics of birth outcomes
local vars "births_all births_male births_female births_HSP births_NHB deaths_all deaths_male deaths_female deaths_HSP deaths_NHB deaths_neonat_all deaths_neonat_male deaths_neonat_female deaths_neonat_HSP deaths_neonat_NHB infant_mortality_rate infant_mortality_HSP infant_mortality_NHB imr imr_NHB imr_HSP births_birthweight_all births_birthweight_NHB births_birthweight_HSP births_birthweight_male births_birthweight_female births_gestation_all births_gestation_male births_gestation_female births_gestation_NHB births_gestation_HSP ptb_rate ptb_rate_NHB ptb_rate_HSP ptb_rate_male ptb_rate_female"

eststo clear 
eststo summary: quietly estpost summarize `vars' 

esttab summary, ///
    cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)) count(fmt(0))") ///
    nomtitle nonumber 

esttab summary using "summary_statistics_birth.tex", tex replace ///
    cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)) count(fmt(0))") ///
    nomtitle nonumber 

eststo clear


****************************************************************
**                 Balance Test Table                         **
****************************************************************

* Let's create a balance test table with means, standard deviations, and p-values for the mean differences of important characteristics between two groups (e.g., a treatment group and a control group)




*********************************************************************************
** Table A3: Balance of County Characteristics:Never vs.Ever Female Adopters   **                      
*********************************************************************************

***************Never elected any female vs Elected at least one**********
clear all
* Import covariates file
use "`datapath'\all_covariates", clear 
* Election data ranges from 1989 to 2021; limit the covariates to this ranges
keep if inrange(year, 1989, 2021)
tempfile tempdata
    save `tempdata' 

* Import the cleaned county-level election data
use "`datapath'\county_election.dta"
merge 1:1 county_fips year using `tempdata'
keep if _merge==3
drop _merge


*We have "never_female" variable equal to 1 if the county never elected any female
gen treated=0
replace treated=1 if never_female==0


*Keep only PRE-treatment years
*For treated counties: years < year_female
*Here we use entire window for never-treated.

gen pre_period = (year < year_female) if treated==1
replace pre_period = 1 if treated==0
keep if pre_period==1




* Varibles included in this balance test: LaborForce Employed UnemploymentRate Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus code2013 earnings transfers. The control group is "Never elected any racial minority" now. 

*Collapse to county-level pre-treatment AVERAGES

local vars LaborForce Employed UnemploymentRate Unemployed ///
           pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian ///
           pop_hispanic pop_nonhispanic ///
           pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus ///
           earnings transfers ///
           share_female share_black share_hispanic share_asian share_democrat ///
           code2013

collapse (mean) `vars', by(county_fips treated)

* Define a local macro with all the "number" variables
local vars "LaborForce Employed Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus earnings transfers"

* Loop through each variable and scale it down by dividing by 1,000
foreach var of local vars {
    replace `var' = `var' / 1000
}



* Check for balance between the treatment and control groups

local vars "share_female share_black share_hispanic share_asian share_democrat LaborForce Employed UnemploymentRate Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus code2013 earnings transfers"

eststo clear 
eststo control: quietly estpost summarize `vars' if treated == 0

eststo treatment: quietly estpost summarize `vars' if treated == 1 
eststo diff: quietly estpost ttest `vars', by(treated) unequal
esttab control treatment diff,cells("mean(pattern(1 1 0) fmt(3)) sd(pattern(1 1 0)) b(star pattern(0 0 1) fmt(3) label(Difference)) p(pattern(0 0 1) par fmt(3) label(p-value))") 

esttab control treatment diff using balance_female_never.tex, replace tex cells("mean(pattern(1 1 0) fmt(3)) sd(pattern(1 1 0)) b(star pattern(0 0 1) fmt(3) label(Difference)) p(pattern(0 0 1) par fmt(3) label(p-value))") 


eststo clear


************************************************************************************************************
** Table A4: Balance of County Characteristics:Never vs. Ever Minority(Black,Hispanic, or Asian)Adopters  **                      
************************************************************************************************************

***************Never elected any racial minority vs Elected at least one**********
clear all
* Import covariates file
use "`datapath'\all_covariates", clear 
* Election data ranges from 1989 to 2021; limit the covariates to this ranges
keep if inrange(year, 1989, 2021)
tempfile tempdata
    save `tempdata' 

* Import the cleaned county-level election data
use "`datapath'\county_election.dta"
gen never_all_race = (never_black & never_hispanic & never_asian)	

merge 1:1 county_fips year using `tempdata'
keep if _merge==3
drop _merge

* Varibles included in this balance test: LaborForce Employed UnemploymentRate Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus code2013 earnings transfers. The control group is "Never elected any racial minority" now. 


*We have "never_all_race" variable equal to 1 if the county never elected any racial minority group 
gen treated=0
replace treated=1 if never_all_race==0

egen min_year = rowmin(year_black year_hispanic year_asian)
*Keep only PRE-treatment years
*For treated counties: years < min_year
*Here we use entire window for never-treated.

gen pre_period = (year < min_year) if treated==1
replace pre_period = 1 if treated==0
keep if pre_period==1

*Collapse to county-level pre-treatment AVERAGES

local vars LaborForce Employed UnemploymentRate Unemployed ///
           pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian ///
           pop_hispanic pop_nonhispanic ///
           pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus ///
           earnings transfers ///
           share_female share_black share_hispanic share_asian share_democrat ///
           code2013

collapse (mean) `vars', by(county_fips treated)

* Define a local macro with all the "number" variables
local vars "LaborForce Employed Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus earnings transfers"

* Loop through each variable and scale it down by dividing by 1,000
foreach var of local vars {
    replace `var' = `var' / 1000
}



* Check for balance between the treatment and control groups

local vars "share_female share_black share_hispanic share_asian share_democrat LaborForce Employed UnemploymentRate Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus code2013 earnings transfers"

eststo clear 
eststo control: quietly estpost summarize `vars' if treated == 0

eststo treatment: quietly estpost summarize `vars' if treated == 1 
eststo diff: quietly estpost ttest `vars', by(treated) unequal
esttab control treatment diff,cells("mean(pattern(1 1 0) fmt(3)) sd(pattern(1 1 0)) b(star pattern(0 0 1) fmt(3) label(Difference)) p(pattern(0 0 1) par fmt(3) label(p-value))") 

esttab control treatment diff using balance_race_never.tex, replace tex cells("mean(pattern(1 1 0) fmt(3)) sd(pattern(1 1 0)) b(star pattern(0 0 1) fmt(3) label(Difference)) p(pattern(0 0 1) par fmt(3) label(p-value))") 


eststo clear





*********************************************************************************
** Table A5:Balance of County Characteristics:Early vs. Late FemaleAdopters    **                      
*********************************************************************************

***************Early vs Late Elected female**********
clear all
* Import covariates file
use "`datapath'\all_covariates", clear 
* Election data ranges from 1989 to 2021; limit the covariates to this ranges
keep if inrange(year, 1989, 2021)
tempfile tempdata
    save `tempdata' 

* Import the cleaned county-level election data
use "`datapath'\county_election.dta"
merge 1:1 county_fips year using `tempdata'
keep if _merge==3
drop _merge


*Define early vs late adopters
*compute cutoff automatically from the distribution)
quietly summarize year_female if !missing(year_female), detail
local cutoff = r(p50)
gen adopter = .
drop if missing(year_female)
replace adopter = 1 if year_female <= `cutoff'
replace adopter = 0 if year_female >  `cutoff'

*Keep only pre-treatment years per county
gen pre_period = (year < year_female)
keep if pre_period==1

* Varibles included in this balance test: LaborForce Employed UnemploymentRate Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus code2013 earnings transfers. The control group is "Never elected any racial minority" now. 

*Collapse to county-level pre-treatment averages (ONE ROW PER COUNTY)
local vars  LaborForce Employed UnemploymentRate Unemployed ///
            pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian ///
            pop_hispanic pop_nonhispanic ///
            pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus ///
            earnings transfers ///
            share_female share_black share_hispanic share_asian share_democrat ///
            code2013

collapse (mean) `vars', by(county_fips adopter)

* Define a local macro with all the "number" variables
local vars "LaborForce Employed Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus earnings transfers"

* Loop through each variable and scale it down by dividing by 1,000
foreach var of local vars {
    replace `var' = `var' / 1000
}



* Check for balance between the treatment and control groups

local vars "share_female share_black share_hispanic share_asian share_democrat LaborForce Employed UnemploymentRate Unemployed pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus code2013 earnings transfers"

eststo clear 
eststo control: quietly estpost summarize `vars' if adopter == 0

eststo treatment: quietly estpost summarize `vars' if adopter == 1 
eststo diff: quietly estpost ttest `vars', by(adopter) unequal
esttab control treatment diff,cells("mean(pattern(1 1 0) fmt(3)) sd(pattern(1 1 0)) b(star pattern(0 0 1) fmt(3) label(Difference)) p(pattern(0 0 1) par fmt(3) label(p-value))") 

esttab control treatment diff using balance_female_early_late.tex, tex cells("mean(pattern(1 1 0) fmt(3)) sd(pattern(1 1 0)) b(star pattern(0 0 1) fmt(3) label(Difference)) p(pattern(0 0 1) par fmt(3) label(p-value))") 


eststo clear



*********************************************************************************
**                             END                                             **                      
*********************************************************************************










